//
//  HUDLayer.m
//  SpeedTap
//
//  Created by Chi Ho Chiu on 21/8/11.
//  Copyright 2011 Individual. All rights reserved.
//

#import "HUDLayer.h"
#import "constant.h"

@implementation HUDLayer
@synthesize timeLeftLabel;
@synthesize remainingTime, totalTime;
@synthesize timeBarSprite, timeLeftSprite;
@synthesize delegate;

-(id) init
{
    if( (self = [super initWithColor:ccc4(0,255,0,60)]) )
    { 
		//Set Content Size
		CGSize winSize = [[CCDirector sharedDirector] winSize];
		const float hudLayerHeight = HUD_LAYER_Y_RATIO;
        [self setContentSize: CGSizeMake(winSize.width, winSize.height * hudLayerHeight)];
		
		//Get Content Size
		CGSize contentSize = [self contentSize];
		
		//Setup TimeLeftLabel
		self.timeLeftLabel = [CCLabelBMFont labelWithString:@"Time Left" fntFile:@"Dakota_white_16.fnt"];
		[self.timeLeftLabel setPosition:CGPointMake([timeLeftLabel contentSize].width/2, 
													contentSize.height - [timeLeftLabel contentSize].height/2)];
		[self addChild:timeLeftLabel];
		
		//Setup timeBarSprite
		
		/*
        int iCurrentPosX = 0;
        int iCurrentPosY = [self contentSize].height/2;
         
        CCLabelBMFont *staticRemainTime = [CCLabelBMFont labelWithString:@"Time: " fntFile:@"Dakota_white_24.fnt"];
        [staticRemainTime setPosition: ccp( iCurrentPosX + [staticRemainTime contentSize].width/2, iCurrentPosY) ];
        [self addChild:staticRemainTime];
        
        iCurrentPosX += [staticRemainTime contentSize].width;
        
        self.remainTimeLabel = [CCLabelBMFont labelWithString:@"00.00" fntFile:@"Dakota_white_24.fnt"];
        [remainTimeLabel setPosition:ccp( iCurrentPosX + [remainTimeLabel contentSize].width/2, iCurrentPosY )];
        [self addChild:remainTimeLabel];
        
        iCurrentPosX += [remainTimeLabel contentSize].width;
        
        CCLabelBMFont *exitFont = [CCLabelBMFont labelWithString:@"Exit" fntFile:@"Dakota_white_24.fnt"];
        CCMenuItem *exitLabel = [CCMenuItemLabel itemWithLabel:exitFont target:self selector:@selector(onMenuItemClicked:)];
        [exitLabel setTag:kHUD_TAG_EXIT];
                
        self.menu = [CCMenu menuWithItems:exitLabel, nil];
        [menu setPosition: ccp( [self contentSize].width * 0.9, [self contentSize].height/2 ) ];
        [self addChild:menu];
		*/
    }
    
    return self;
}

-(void) dealloc
{
	//Release
    [timeLeftLabel release];
    [timeBarSprite release];
	[timeLeftSprite release];

    [super dealloc];
}

//Over-ride setRemainingTime function
-(void) setRemainingTime:(float)time
{
	self.remainingTime = time;
	
	//Update the Sprite length as well
	[self.timeLeftSprite setScaleX:self.remainingTime / self.totalTime];
}

@end
